﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Zhuang.WinForm.BasicDataSetting;
using Zhuang.WinForm.Sales;

namespace Zhuang.WinForm
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private void Main_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
        

        private void Main_Load(object sender, EventArgs e)
        {
            do_桌面();

        }

        private bool HaveOpened(Form parentForm, string subFormClassName)
        {
            //查看窗口是否已经被打开
            bool bReturn = true;
            for (int i = 0; i < parentForm.MdiChildren.Length; i++)
            {
                if (parentForm.MdiChildren[i].Name == subFormClassName)
                {

                    parentForm.MdiChildren[i].BringToFront();
                    //parentForm.MdiChildren[i].WindowState = FormWindowState.Maximized;
                    bReturn = false;
                    break;
                }
            }
            return bReturn;
        }


        private void do_桌面()
        {
            Desktop d = new Desktop();


            if (HaveOpened(this, "Desktop"))
            {
                d.MdiParent = this;
                d.WindowState = FormWindowState.Maximized;
                d.Show();
            }
        }

        private void 商品管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            do_商品管理();
        }

        private void do_商品管理()
        {
            ProductList form = new ProductList();

            if (HaveOpened(this, "ProductList"))
            {
                form.MdiParent = this;
                form.Show();
            }
        }

        private void 付款收银ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            do_付款收银();
        }

        private void do_付款收银()
        {
            Pos form = new Pos();

            if (HaveOpened(this, "Pos"))
            {
                form.MdiParent = this;
                form.Show();
            }
        }

        private void 零售POSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            do_零售POS();
        }

        private void do_零售POS()
        {
            Reports.Sales.PosMaster form = new Reports.Sales.PosMaster();

            if (HaveOpened(this, "PosMaster"))
            {
                form.MdiParent = this;
                form.Show();
            }
        }
    }
}
